package com.qeegoo.b2bautozityp.widget;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.widget.TextView;

import com.cropper.imagepicker.ImagePicker;
import com.flyco.animation.SlideEnter.SlideBottomEnter;
import com.flyco.animation.SlideExit.SlideBottomExit;
import com.flyco.dialog.widget.base.BottomBaseDialog;
import com.qeegoo.b2bautozityp.R;

import base.lib.util.ActivityManager;

/**
 * 王少岩 在 2017/9/15 创建了它
 */

public class ChoosePicDialog extends BottomBaseDialog<ChoosePicDialog> {
    private Context mContext;
    private TextView mTvCamera, mTvChoose, mTvCancel;
    private ImagePicker mImagePicker;
    private PickImgListener mPickImgListener;

    public ChoosePicDialog(Context context, ImagePicker imagePicker, PickImgListener listener) {
        super(context);
        mContext = context;
        mImagePicker = imagePicker;
        mPickImgListener = listener;
    }

    @Override
    public View onCreateView() {
        showAnim(new SlideBottomEnter());
        dismissAnim(new SlideBottomExit());
        View inflate = View.inflate(mContext, R.layout.layout_choose_pic, null);
        mTvCamera = (TextView) inflate.findViewById(R.id.tv_camera);
        mTvChoose = (TextView) inflate.findViewById(R.id.tv_choose);
        mTvCancel = (TextView) inflate.findViewById(R.id.tv_cancel);
        return inflate;
    }

    @Override
    public void setUiBeforShow() {
        mTvCamera.setOnClickListener(v -> {
        });
        mTvChoose.setOnClickListener(v -> {
            dismiss();
            mImagePicker.startGallery(ActivityManager.getActivity(), new ImagePicker.Callback() {
                @Override
                public void onPickImage(Uri imageUri) {
                    if (mPickImgListener != null)
                        mPickImgListener.pickImg(imageUri);
                }
            });
        });
        mTvCancel.setOnClickListener(v -> dismiss());
    }

    public interface PickImgListener {
        void pickImg(Uri imageUri);
    }
}
